﻿@{
    Layout = null;
    var objQueryColumns = Model.ColumnInfos.Where(c => c.IsQuery).ToList();
    var objNotQueryColumns = Model.ColumnInfos.Where(c => c.IsDisplay).ToList();
    var objFormatters = objNotQueryColumns.Where(c=>c.Formatter.IsNoNull()).ToList();
    var objPrimaryKey = objNotQueryColumns.First();
    string entityName = Model.Name.ToLower();
}@inherits  BuildCodeViewPage<TableInfo>
@@{
    ViewBag.Title = "@Model.Description";
    Layout = "~/Views/Shared/_ListLayout.cshtml";
}
@@inherits CMSWebViewPage<object>
@@section Head{

}
<div id="toolbar_@entityName" class="datagrid-toolbar">
    @@CurrentButtonTool.Create()
    @if(objQueryColumns.IsNoNull())
    {
        string noticeType = string.Empty;
    <div>
        <form id="fr_search_@entityName">
@foreach(var objColumnInfo in objQueryColumns)
{
    noticeType = CurrentBuilder.GetNoticeType(objColumnInfo.DataType, objColumnInfo.IsNull);
    switch(noticeType)
    {
        case "string":
            <tj>@@Html.QueryStringBox("@objColumnInfo.Description", "@objColumnInfo.Name")</tj>
            break;
        case "int":
        case "int?":
            <tj>@@Html.QueryComboBox("@objColumnInfo.Description", "@objColumnInfo.Name", new List<SelectListItem>
           {

           })</tj>
            break;
        case "DateTime":
        case "DateTime?":
            <tj>@@Html.QueryDateTimeBox("@objColumnInfo.Description", "@objColumnInfo.Name")-@@Html.QueryDateTimeBox("", "@objColumnInfo.Name", QueryMethod.LessEqual, QueryDataType.DateTime)</tj>
            break;
    }
}
            <a onclick="Search();" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true"></a>
        </form>
    </div>
    }
</div>
<table id="dg_@entityName" data-options="url:'/@entityName/listjson',border:false,fit:true,fitColumns:true,toolbar:'#toolbar_@entityName',singleSelect:true,pagination:true,pageSize:20">
    <thead>
        <tr>
            <th data-options="field:'ck',checkbox:true"></th>
        @if(objNotQueryColumns.IsNoNull())
        {
            foreach (var objColumnInfo in objNotQueryColumns)
            {
            <th data-options="field:'@objColumnInfo.Name',width:@objColumnInfo.Width,@(objColumnInfo.Formatter.IsNoNull()?objColumnInfo.Formatter.FormatSelf("formatter:{0},"):"")align:'center'">@objColumnInfo.Description</th>
            }
        }
        </tr>
    </thead>
</table>
@@section Bottom{
    <script type="text/javascript">
        var objBizDatagrid = new BizDatagrid('#dg_@entityName');
        function Add() {
            objBizDatagrid.add("/@entityName/editpage");
        }
        function Edit() {
            objBizDatagrid.edit("/@entityName/editpage", "@objPrimaryKey.Name.ToFirstUpper()");
        }
        function Search() {
            objBizDatagrid.search('#fr_search_@entityName', '/@entityName/listjson');
        }
        function Delete() {
            objBizDatagrid.del('/@entityName/delete', "@objPrimaryKey.Name.ToFirstUpper()");
        }
        @if(objFormatters.IsNoNull())
        {
foreach (var objFormatterColumnInfo in objFormatters)
{
    if (!string.Equals("BooleanToString", objFormatterColumnInfo.Formatter) && !string.Equals("JsonToDate", objFormatterColumnInfo.Formatter))
    {
        <tj>function @(objFormatterColumnInfo.Formatter)(val, row) {
            var result = "";
            switch (val)
            {
                case "":
                    result = "";
                    break;
            }
            return val;
        }</tj>    
    }
}
        }
    </script>
}
